#!/sbin/openrc-run

description="Jitsi Conference Focus"

pidfile="/var/run/jicofo/jicofo.pid"
# launcher script below will work on OpenRC also
command="/usr/share/jicofo/jicofo.sh"
command_args=" --host=$JICOFO_HOST --domain=$JICOFO_HOSTNAME --port=$JICOFO_PORT --user_name=$JICOFO_AUTH_USER --user_domain=$JICOFO_AUTH_DOMAIN ${JICOFO_OPTS}"
command_user="jicofo:jitsi"
command_background=true

depend() {
	need net
	want jabber-server
}

start_pre() {
	checkpath -d -o $command_user -m 770 /var/run/jicofo
}

start() {
	ebegin "Starting ${name}"
	export JICOFO_SECRET JICOFO_AUTH_PASSWORD JICOFO_MAX_MEMORY
	start-stop-daemon --start --quiet --background --chuid $command_user \
		-m --pidfile $pidfile \
		--exec /bin/bash -- -c "JAVA_SYS_PROPS=\"$JAVA_SYS_PROPS\" exec $command $command_args >> $JICOFO_LOGFILE 2>&1"
	eend $?
}
